package com.xintouyun.medicine.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.xintouyun.medicine.entity.User;
import com.xintouyun.medicine.service.UserService;
import com.xintouyun.medicine.service.impl.UserServiceImpl;
@WebServlet("/UserUpdateServlet")
public class UserUpdateServlet extends HttpServlet{

	
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpSession session =request.getSession();
		User user = (User) session.getAttribute("loginUser");
		
		String oldupwd = request.getParameter("oldUpwd");
		String upwd = request.getParameter("upwd");
		System.out.println("========="+oldupwd);
		System.out.println("++++++++++"+upwd);
		if(oldupwd.equals(user.getUpwd())) {
			UserService userService = new UserServiceImpl();
			int i = userService.update(upwd,user.getUid());
			request.getRequestDispatcher("member-setting-safe.jsp").forward(request, response);;
		}else {
			request.getRequestDispatcher("member-setting-safe.jsp").forward(request, response);;
		}
		
	}
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doGet(request, response);
	}
}
